from nicegui import ui


# 临时做法，此文件同目录下带 editor.js
class MyEditor(ui.editor, component="editor.js"):
    pass


@ui.page("/")
def page():
    ui.on("save_file", lambda e: print(f"点击了 保存 按钮: {e.args}"))
    editor = MyEditor()

    editor._props["definitions"] = {
        "save": {
            "tip": "Save the current file",
            "icon": "save",
            "label": "Save",
            ":handler": '()=> { emitEvent("save_file", "参数1")}',
        }
    }

    editor._props["toolbar"] = [["bold", "italic", "strike", "underline"], ["save"]]
    editor.update()


ui.run()
